//
//  ZYCTeaAttendanceClockInStatisticsView.m
//  ZDSC
//
//  Created by 张威 on 2021/11/8.
//

#import "ZYCTeaAttendanceClockInStatisticsView.h"
#import "ZYCTeaLeaveRecordModel.h"

@interface ZYCTeaAttendanceClockInStatisticsView ()

@property (nonatomic, strong) UILabel *tipLabel;
@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UIView *top;
@property (nonatomic, strong) UIView *bottom;
@property (nonatomic, strong) UIView *line;


@property (nonatomic, strong) UILabel *workTimeLabel;
@property (nonatomic, strong) UILabel *workStatusLabel;
// 上午请假
@property (nonatomic, strong) UILabel *leaveTimeLabel;
@property (nonatomic, strong) UILabel *workTemperatureLabel;


@property (nonatomic, strong) UILabel *restTimeLabel;
@property (nonatomic, strong) UILabel *restStatusLabel;
// 下午请假
@property (nonatomic, strong) UILabel *restLeaveTimeLabel;
@property (nonatomic, strong) UILabel *restTemperatureLabel;



@end
@implementation ZYCTeaAttendanceClockInStatisticsView

- (void)setModel:(ZYCTeaLeaveRecordModel *)model{
    _model = model;
    if (model.goToWorkTime.length > 0) {
        _workTimeLabel.textColor = HEX_RGB(@"#333333");
        _workTimeLabel.text = [NSString stringWithFormat:@"上班%@",model.goToWorkTime];
    }else{
        _workTimeLabel.textColor = HEX_RGB(@"#D8D8D8");
        _workTimeLabel.text = @"上班08:00";
    }
    //（1-正常、2-迟到、3-早退、4-缺卡、5-请假、6-加班）
    if ([model.attendanceStatus integerValue] == 1) {// 正常
        _workStatusLabel.backgroundColor = HEX_RGB(@"#41B166");//绿色
        _workTemperatureLabel.hidden = NO;
    }else  if ([model.attendanceStatus integerValue] == 2 || [model.attendanceStatus integerValue] == 3) {//迟到 || 早退
        _workStatusLabel.backgroundColor = HEX_RGB(@"#EC4402");
        _workTemperatureLabel.hidden = NO;
    }else if([model.attendanceStatus integerValue] == 4){// 缺卡
        _workStatusLabel.backgroundColor = HEX_RGB(@"#C1C1C1");
        _workTemperatureLabel.hidden = YES;
        [self.leaveTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.workTimeLabel);
            make.top.equalTo(self.workTimeLabel.mas_bottom).offset(5.0f);
        }];
    }else if([model.attendanceStatus integerValue] == 5){// 请假
        _workStatusLabel.backgroundColor = HEX_RGB(@"#FDAC5C"); //黄色
        _workTemperatureLabel.hidden = YES;
//
        [self.leaveTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.workTimeLabel);
            make.top.equalTo(self.workTimeLabel.mas_bottom).offset(5.0f);
        }];

    }else if([model.endAttendanceStatus integerValue] == 6){// 加班
        _workStatusLabel.backgroundColor = HEX_RGB(@"#2B7BBF");
        _workTemperatureLabel.hidden = NO;
    }
    
    if (model.leaveTime.length > 0) {// 上午请假
        _leaveTimeLabel.hidden = NO;
        _leaveTimeLabel.text = [NSString stringWithFormat:@"请假时间:%@",model.leaveTime];
        
    }else{
        _leaveTimeLabel.hidden = YES;
    }
    
    
    if (model.leaveEndTime.length > 0) { //下午请假
        _restLeaveTimeLabel.hidden = NO;
        _restLeaveTimeLabel.text = [NSString stringWithFormat:@"请假时间:%@",model.leaveEndTime];
    }else{
        _restLeaveTimeLabel.hidden = YES;
    }
    
    if ([model.endAttendanceStatus integerValue] == 1) {// 正常
        _restStatusLabel.backgroundColor =  HEX_RGB(@"#41B166");
        _restTemperatureLabel.hidden = NO;
    }else   if ([model.endAttendanceStatus integerValue] == 2 || [model.endAttendanceStatus integerValue] == 3) {//迟到 || 早退
        _restStatusLabel.backgroundColor = HEX_RGB(@"#EC4402");
        _restTemperatureLabel.hidden = NO;
    }else if([model.endAttendanceStatus integerValue] == 4){// 缺卡
        _restStatusLabel.backgroundColor = HEX_RGB(@"#C1C1C1");
        _restTemperatureLabel.hidden = YES;
        [self.restLeaveTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.restTimeLabel);
            make.top.equalTo(self.restTimeLabel.mas_bottom).offset(5.0f);
        }];
    }else if([model.endAttendanceStatus integerValue] == 5){// 请假
        _restStatusLabel.backgroundColor = HEX_RGB(@"#FDAC5C");
        _restTemperatureLabel.hidden = YES;
        [self.restLeaveTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.restTimeLabel);
            make.top.equalTo(self.restTimeLabel.mas_bottom).offset(5.0f);
        }];
    }else if([model.endAttendanceStatus integerValue] == 6){// 请假
        _restStatusLabel.backgroundColor = HEX_RGB(@"#2B7BBF");
        _restTemperatureLabel.hidden = NO;
    }
    _workStatusLabel.text = model.attendanceStatusStr;
    
    NSString *workTemperature = nil;
    if (model.temperature.length == 0) {
        workTemperature = @"温度:无";
    }else{
        workTemperature = [NSString stringWithFormat:@"温度:%@",model.temperature];
    }
    
    _workTemperatureLabel.text = workTemperature;
    _restTemperatureLabel.text = workTemperature;
    
    if (model.goOffWorkTime.length > 0) {
        _restTimeLabel.textColor = HEX_RGB(@"#333333");
        _restTimeLabel.text = [NSString stringWithFormat:@"下班%@",model.goOffWorkTime];
    }else{
        _restTimeLabel.textColor = HEX_RGB(@"#D8D8D8");
        _restTimeLabel.text = @"下班17:00";
    }
    _restStatusLabel.text = model.endAttendanceStatusStr;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.tipLabel];
        [self addSubview:self.bgView];
        [self.bgView addSubview:self.top];
        [self.bgView addSubview:self.bottom];
        [self.bgView addSubview:self.line];
        [self.bgView addSubview:self.workTimeLabel];
        [self.bgView addSubview:self.workStatusLabel];
        [self.bgView addSubview:self.workTemperatureLabel];
        [self.bgView addSubview:self.leaveTimeLabel];
        
        [self.bgView addSubview:self.restTimeLabel];
        [self.bgView addSubview:self.restStatusLabel];
        [self.bgView addSubview:self.restTemperatureLabel];
        [self.bgView addSubview:self.restLeaveTimeLabel];
        
        [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10.0f);
            make.top.equalTo(self).offset(20.0f);
        }];
        
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10.0f);
            make.top.equalTo(self.tipLabel.mas_bottom).offset(15.0f);
            make.bottom.right.equalTo(self).offset(-10.0f);
        }];
        
        [self.top mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgView).offset(10.0f);
            make.centerY.equalTo(self.workTimeLabel);
            make.size.mas_equalTo(CGSizeMake(12.5, 12.5));
        }];
        
        [self.workTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.top.mas_right).offset(10.0f);
            make.top.equalTo(self.bgView).offset(20.0f);
        }];
        
        [self.workStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.workTimeLabel.mas_right).offset(10.0f);
            make.centerY.equalTo(self.workTimeLabel);
            make.size.mas_equalTo(CGSizeMake(49.0f, 19.0f));
        }];
        
        [self.workTemperatureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.workTimeLabel);
            make.top.equalTo(self.workTimeLabel.mas_bottom).offset(8.5f);
        }];
        
        [self.leaveTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.workTimeLabel);
            make.top.equalTo(self.workTemperatureLabel.mas_bottom).offset(5.0f);
        }];
        

        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.top);
            make.top.equalTo(self.top.mas_bottom);
            make.width.mas_equalTo(2.0f);
            make.bottom.equalTo(self.bottom.mas_top);
            make.height.mas_equalTo(80.0f);
        }];
        
        [self.bottom mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.top);
            make.centerY.equalTo(self.restTimeLabel);
            make.size.mas_equalTo(CGSizeMake(12.5, 12.5));
        }];
        
        
        [self.restTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bottom.mas_right).offset(10.0f);
            make.bottom.equalTo(self.restTemperatureLabel.mas_top).offset(-8.5f);
        }];
        
        [self.restStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.restTimeLabel.mas_right).offset(10.0f);
            make.centerY.equalTo(self.restTimeLabel);
            make.size.mas_equalTo(CGSizeMake(49.0f, 19.0f));
        }];
        
        [self.restTemperatureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.restTimeLabel);
            make.top.equalTo(self.restTimeLabel.mas_bottom).offset(5.0f);
        }];
        
        [self.restLeaveTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.restTimeLabel);
            make.top.equalTo(self.restTemperatureLabel.mas_bottom).offset(5.0f);
            make.bottom.equalTo(self.bgView.mas_bottom).offset(-10.0f);
        }];
    }
    return self;
}


#pragma mark - getters

- (UILabel *)tipLabel {
    if (!_tipLabel) {
        _tipLabel = [UILabel LabelWithString:@"上下班时间：周一至周五 08:00-17:00" Font:kCustomFont(@"PingFangSC-Regular", 14.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _tipLabel;
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = HEX_RGB(kBgWhiteColor);
        _bgView.layer.cornerRadius = 7.5f;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}



- (UIView *)top {
    if (!_top) {
        _top = [[UIView alloc] init];
        _top.backgroundColor = HEX_RGB(@"#CECECE");
        _top.layer.cornerRadius = 12.5 / 2;
        _top.layer.masksToBounds = YES;
    }
    return _top;
}

- (UIView *)bottom {
    if (!_bottom) {
        _bottom = [[UIView alloc] init];
        _bottom.backgroundColor = HEX_RGB(@"#CECECE");
        _bottom.layer.cornerRadius = 12.5/ 2;
        _bottom.layer.masksToBounds = YES;
    }
    return _bottom;
}

- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = HEX_RGB(@"#CECECE");
    }
    return _line;
}

- (UILabel *)workTimeLabel {
    if (!_workTimeLabel) {
        _workTimeLabel = [[UILabel alloc] init];
        _workTimeLabel.font = kCustomFont(@"PingFangSC-Regular", 20.0f);
        _workTimeLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _workTimeLabel;
}

- (UILabel *)workStatusLabel {
    if (!_workStatusLabel) {
        _workStatusLabel = [[UILabel alloc] init];
        _workStatusLabel.textColor = HEX_RGB(@"FFFFFF");
        _workStatusLabel.layer.cornerRadius = 10.0f;
        _workStatusLabel.layer.masksToBounds = YES;
        _workStatusLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _workStatusLabel;
}

- (UILabel *)workTemperatureLabel {
    if (!_workTemperatureLabel) {
        _workTemperatureLabel = [UILabel LabelWithString:@"温度:" Font:kCustomFont(@"PingFangSC-Regular", 15.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _workTemperatureLabel;
}

- (UILabel *)restTimeLabel {
    if (!_restTimeLabel) {
        _restTimeLabel = [[UILabel alloc] init];
        _restTimeLabel.font = kCustomFont(@"PingFangSC-Regular", 20.0f);
        _restTimeLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _restTimeLabel;
}

- (UILabel *)leaveTimeLabel {
    if (!_leaveTimeLabel) {
        _leaveTimeLabel =[UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 15.0f) titleColor:HEX_RGB(@"#FDAC5C") textAlignment:ZZTextAlignmentLeft];
    }
    return _leaveTimeLabel;
}

- (UILabel *)restLeaveTimeLabel {
    if (!_restLeaveTimeLabel) {
        _restLeaveTimeLabel =[UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 15.0f) titleColor:HEX_RGB(@"#FDAC5C") textAlignment:ZZTextAlignmentLeft];
    }
    return _restLeaveTimeLabel;
}

- (UILabel *)restStatusLabel {
    if (!_restStatusLabel) {
        _restStatusLabel = [[UILabel alloc] init];
        _restStatusLabel.textColor = HEX_RGB(@"FFFFFF");
        _restStatusLabel.layer.cornerRadius = 10.0f;
        _restStatusLabel.layer.masksToBounds = YES;
        _restStatusLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _restStatusLabel;
}

- (UILabel *)restTemperatureLabel {
    if (!_restTemperatureLabel) {
        _restTemperatureLabel = [UILabel LabelWithString:@"温度:" Font:kCustomFont(@"PingFangSC-Regular", 15.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _restTemperatureLabel;
}



@end
